package com.tjetc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjetc.vo.ClinicInfoVo;
import com.tjetc.vo.Result;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.tjetc.mapper.ClinicMapper;
import com.tjetc.domain.Clinic;
import com.tjetc.service.ClinicService;

import java.util.List;

@Service
public class ClinicServiceImpl implements ClinicService{

    @Resource
    private ClinicMapper clinicMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return clinicMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Clinic record) {
        return clinicMapper.insert(record);
    }

    @Override
    public int insertSelective(Clinic record) {
        return clinicMapper.insertSelective(record);
    }

    @Override
    public Clinic selectByPrimaryKey(Integer id) {
        return clinicMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Clinic record) {
        return clinicMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Clinic record) {
        return clinicMapper.updateByPrimaryKey(record);
    }

    @Override
    public Result findByName(Integer hid, String name) {
        List<Clinic> clinics = clinicMapper.findByName(hid, name);
        return Result.ok(clinics);
    }

    @Override
    public Result getClinicInfo(Integer cid) {
        ClinicInfoVo clinicInfo= clinicMapper.getClinicInfo(cid);
        return Result.ok(clinicInfo);
    }

    @Override
    public Result getClinicById(Integer id) {
        Clinic clinic = clinicMapper.selByIdWithHos(id);
        return Result.ok(clinic);
    }

    @Override
    public Result getAll(Integer hid) {
        List<Clinic> clinics = clinicMapper.getAll(hid);
        return Result.ok(clinics);
    }


    @Override
    public PageInfo<Clinic> selAllname(String name, Integer curPage, Integer pageSize,Integer hid) {
        PageHelper.startPage(curPage,pageSize);
        if (hid == null){
            return new PageInfo<>(clinicMapper.selAllname(name));
        }else {
            return new PageInfo<>(clinicMapper.selByNameAndHid(name, hid));
        }
    }

    @Override
    public Integer delById(Integer id) {
        return clinicMapper.deleteByPrimaryKey( id);
    }

    @Override
    public Integer update(Clinic clinic) {
        return clinicMapper.updateByPrimaryKeySelective(clinic);
    }

    @Override
    public Integer add(Clinic clinic) {
        return clinicMapper.add(clinic);
    }

}
